package com.skstudio.nuprint.lpd;

import java.io.IOException;
import java.net.Socket;


public class LpdWorkerThread extends Thread {
	Socket mClientSocket = null;
	
	public LpdWorkerThread(Socket s) {
		mClientSocket = s;		
	}
	
	protected static int cThreadCount = 0;
	protected static final int cMaxThreadCount = 10;
	
	public static boolean canCreateNewThread() {
		return cThreadCount < cMaxThreadCount;
	}
	
	@Override 
	public void run() {
		cThreadCount ++;
		
		try {	
			LpdCommand cmd = new LpdCommand(mClientSocket);
			cmd.process();
		} catch(Exception e) {
			e.printStackTrace();
		}
		closeSocket();
		
		cThreadCount --;
	}
	
	protected void closeSocket() {
		try {
			mClientSocket.close();
		} catch (IOException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}	
		mClientSocket = null;
	}
}
